package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class RegisterActivity extends AppCompatActivity {

    private EditText etRegUsername, etRegPassword, etRegConfirmPassword;
    private Button btnRegister;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        etRegUsername = findViewById(R.id.etRegUsername);
        etRegPassword = findViewById(R.id.etRegPassword);
        etRegConfirmPassword = findViewById(R.id.etRegConfirmPassword);
        btnRegister = findViewById(R.id.btnRegister);

        btnRegister.setOnClickListener(v -> {
            String username = etRegUsername.getText().toString().trim();
            String password = etRegPassword.getText().toString().trim();
            String confirmPassword = etRegConfirmPassword.getText().toString().trim();

            if (username.isEmpty()) {
                etRegUsername.setError("请输入用户名");
                return;
            }

            if (password.isEmpty()) {
                etRegPassword.setError("请输入密码");
                return;
            }

            if (!password.equals(confirmPassword)) {
                etRegConfirmPassword.setError("两次输入的密码不一致");
                return;
            }

            Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();

            finish();
        });
    }
}